package org.example.controller;

import org.example.pojo.*;
import org.example.service.CompanyService;
import org.example.service.JobService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
public class CompanyController {
    @Autowired
    private CompanyService companyService;

    @Autowired
    private JobService jobService;

    //分页查询公司列表
    @PostMapping("/company/page")
    public Result<PageBean<Company>> getCompanyList(Integer companyId, String name, Integer pageNum, Integer pageSize) {
        PageBean<Company> pb = companyService.getCompanyList(companyId, name, pageNum, pageSize);
        return Result.success(pb);
    }

    //根据公司id查询公司信息
    @PostMapping("/company/CompanyDetails")
    public Result<Company> getCompanyById(Integer companyId) {
        //根据公司id查询公司信息
        Company company = companyService.getCompanyById(companyId);
        return Result.success(company);
    }

    //获取热门企业及其岗位
    @GetMapping("/company/getHotCompanyList")
    public Result<List<CompanyDto>> getHotCompanyList() {
        int[] companyId = {54, 60, 130};
        List<CompanyDto> companyDtoList = new ArrayList<>();
        for (int i = 0; i < companyId.length; i++) {
            CompanyDto companyDto = new CompanyDto();
            Company company = companyService.selectByCompanyId(companyId[i]);
            List<Job> companyJobList = jobService.getCompanyJobList(companyId[i]);
            companyDto.setCompany(company);
            companyDto.setJobList(companyJobList);
            companyDtoList.add(companyDto);
        }
        return Result.success(companyDtoList);
    }


}
